package com.hs.pre.model;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class ProfileBean {

	private Long id;
	
	private String loginId;
	
	private String configStr;
	
	/**
	 *  是否使用
	 */
	private Integer isUse;
	
	/**
	 * 显示行数
	 * 默认10
	 */
	private Integer viewNum =10;
	
	/****
	 * key 为序列号
	 * value为 BardianBean 对象
	 */
	private Map fileMap = new TreeMap();
	
	private String tableName="default";
	
	public Integer getViewNum() {
		return viewNum;
	}

	public void setViewNum(Integer viewNum) {
		this.viewNum = viewNum;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getLoginId() {
		return loginId;
	}

	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}

	public String getConfigStr() {
		return configStr;
	}

	public void setConfigStr(String configStr) {
		this.configStr = configStr;
		this.init(configStr);
	}
	
	private void init(String configStr)
	{
		if(configStr==null || configStr.trim().equals(""))
			return ;
		JSONObject jsonObject= JSONObject.fromObject(configStr);
		JSONArray jSONArray  = jsonObject.getJSONArray("field");
		this.setTableName(jsonObject.getString("tableName"));
		Iterator iterator = jSONArray.iterator();
		while(iterator.hasNext())
		{
			JSONObject jSONObject =(JSONObject)iterator.next();
			BardianBean bardianBean= new BardianBean();
			bardianBean.setFieldId(jSONObject.getString("fieldId"));
			bardianBean.setFieldName(jSONObject.getString("fieldName"));
			bardianBean.setSerial(jSONObject.getInt("serial"));
			fileMap.put(bardianBean.getSerial(), bardianBean);
		}
		
	}

	public Integer getIsUse() {
		return isUse;
	}

	public void setIsUse(Integer isUse) {
		this.isUse = isUse;
	}

	public Map getFileMap() {
		return fileMap;
	}

	public void setFileMap(Map fileMap) {
		this.fileMap = fileMap;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
}
